package com.atguigu.gmall.index.controller;

import com.agtuigu.gmall.pms.entity.CategoryEntity;
import com.agtuigu.gmall.pms.vo.CategoryVo;
import com.atguigu.core.bean.Resp;
import com.atguigu.gmall.index.service.IndexService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("index")
public class indexController {


    @Resource
    private IndexService indexService;

    @GetMapping("cates")
    public Resp<List<CategoryEntity>> queryLvl1Categories() {
        List<CategoryEntity> categoryEntities = indexService.queryLvl1Categories();
        return Resp.ok(categoryEntities);
    }

    @GetMapping("cates/{pid}")
    public Resp<List<CategoryVo>> querySubCategories(@PathVariable("pid") Long pid) {
        List<CategoryVo> categoryVos = indexService.querySubCategories(pid);
        return Resp.ok(categoryVos);
    }


    @GetMapping("test/lock")
    public String testLock() {
        indexService.testLock();
        return "ok";
    }

}
